#include "proxyadderitem.h"
#include "ui_proxyadderitem.h"

ProxyAdderItem::ProxyAdderItem(QNetworkProxy proxy, QWidget *parent) :
    QFrame(parent),
    ui(new Ui::ProxyAdderItem)
{
    ui->setupUi(this);
    ui->type->setCurrentIndex(proxy.type());
    ui->address->setText(proxy.hostName());
    ui->port->setValue(proxy.port());
    connect(ui->addNew, SIGNAL(clicked()), this, SLOT(duplicate()));
}

void ProxyAdderItem::duplicate(){
    QNetworkProxy proxy;
    (ui->type->currentIndex());
    switch(ui->type->currentIndex()){
    case 0:
        proxy.setType(QNetworkProxy::NoProxy);
        break;
    case 1:
        proxy.setType(QNetworkProxy::Socks5Proxy);
        break;
    }
    proxy.setHostName(ui->address->text());
    proxy.setPort(ui->port->value());
    ProxyAdderItem* tmp=new ProxyAdderItem(proxy);
    emit newProxy(tmp);
};

ProxyAdderItem::~ProxyAdderItem()
{
    delete ui;
}
